package com.hnyfkj.jyindustry.biz.pi.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageInfo;
import com.hnyfkj.jyindustry.biz.pi.dao.PiDao;
import com.hnyfkj.jyindustry.biz.pi.dto.PiInsertDto;
import com.hnyfkj.jyindustry.biz.pi.dto.PiQueryDto;
import com.hnyfkj.jyindustry.biz.pi.dto.PiUpdateDto;
import com.hnyfkj.jyindustry.biz.pi.entity.PiScreen;
import com.hnyfkj.jyindustry.biz.pi.service.PiService;
import com.hnyfkj.jyindustry.biz.pi.vo.PiVo;
import com.hnyfkj.jyindustry.common.dto.PageReturnDto;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.BeanUtils;

import java.util.Arrays;

@Service("piService")
public class PiServiceImpl extends ServiceImpl<PiDao, PiScreen> implements PiService {


    @Autowired
    private PiDao piDao;

    @Override
    public PageReturnDto<PiVo> queryPage(PiQueryDto queryDto) {
        PageInfo<PiVo> page =
                PageHelper.startPage(queryDto.getPage(), queryDto.getLimit()).doSelectPageInfo(() -> piDao.selectListByQuery(queryDto));
        return PageReturnDto.pageOf(page);
    }

    @Override
    public int insert(PiInsertDto piInsertDto) {
        final PiScreen piScreen = new PiScreen();
        BeanUtils.copyProperties(piInsertDto, piScreen);
        return piDao.insert(piScreen);
    }

    @Override
    public int update(PiUpdateDto piUpdateDto) {
        final PiScreen piScreen = new PiScreen();
        BeanUtils.copyProperties(piUpdateDto, piScreen);
        return piDao.updateById(piScreen);
    }

    @Override
    public int delete(String ids) {
        String[] id = ids.split(",");
        return piDao.deleteBatchIds(Arrays.asList(id));
    }
}